//
//  TruckDetailsViewController.m
//  Logistics
//
//  Created by hy002 on 2018/1/18.
//  Copyright © 2018年 HUYU. All rights reserved.
//

#import "TruckDetailsViewController.h"
#import "CarDetailModel.h"
#import "CDZStarsControl.h"
#import "GoodsAddressModel.h"
#import "CommentModel.h"
#import "VanCommentViewController.h"
#import "ComplaintsViewController.h"

static NSString *cellPath = @"TruckDetailsCell";
@interface TruckDetailsViewController ()<UITableViewDelegate,UITableViewDataSource,CDZStarsControlDelegate>
{
    UIButton *focusonBtn;
    UIImage *logoimage;
}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSArray *commentAry;
@property (nonatomic, strong)CarDetailModel *carModel;

@end

@implementation TruckDetailsViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(callPhonesNotifice:) name:@"callPhones" object:nil];
    [self requestTtuckSelect];
    [self requestCommentList];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"callPhones" object:nil];
}


- (void)callPhonesNotifice:(NSNotification *)center
{
    NSString *timeStr = [center object];
    Student *stu = [Student studentWith:_carModel.headImg name:_carModel.linkman Phone:_carModel.phone Times:timeStr];
    BOOL isInsert = [StudentFMDNManager addStudent:stu];
    
    if (isInsert) {
        NSLog(@"插入成功");
    } else {
        NSLog(@"插入失败");
    }
}



- (void)viewDidLoad
{
    [super viewDidLoad];
    [self creatUI];
   
}

- (void)creatUI
{
    self.view.backgroundColor = RGB(245, 245, 245);
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"货车详情";
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX, SCREEN_WIDTH, 50*displaywidth)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    UIButton *commentBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, 7.5*displaywidth, SCREEN_WIDTH-260*displaywidth, 35*displaywidth) ImageName:@"db_nav4" Target:self Action:@selector(commentAction) Title:@" 我要评论" Font:13.0];
    commentBtn.layer.cornerRadius = 2;
    commentBtn.layer.masksToBounds = YES;
    commentBtn.backgroundColor = BacksColor;
    UIEdgeInsets imageViewEdge = UIEdgeInsetsMake(0, 10, 0, 0);
    [commentBtn setImageEdgeInsets:imageViewEdge];
    UIEdgeInsets titLabEdge = UIEdgeInsetsMake(0, 15, 0, 0);
    [commentBtn setTitleEdgeInsets:titLabEdge];
    commentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    commentBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [commentBtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
    [bottomView addSubview:commentBtn];
    NSArray *imgArray = @[@"db_nav7",@"db_nav5",@"db_nav8",@"db_nav6"];
    NSArray *titArray = @[@"分享",@"投诉",@"关注",@"电话"];
    NSArray *colorAry = @[RGB(253, 144, 37),RGB(255, 51, 51),RGB(0, 153, 0),RGB(0, 153, 255)];
    for (int i = 0; i < imgArray.count; i++)
    {
        UIButton *closebtn = [UIButton buttonWithType:UIButtonTypeCustom];
        closebtn.frame = CGRectMake(SCREEN_WIDTH-240*displaywidth+60*displaywidth*i, 0, 60*displaywidth, 50*displaywidth);
        [closebtn setImage:[UIImage imageNamed:imgArray[i]] forState:UIControlStateNormal];
        [closebtn setTitleColor:colorAry[i] forState:UIControlStateNormal];
        [closebtn setTitle:titArray[i] forState:UIControlStateNormal];
        closebtn.titleLabel.font = NormalFontWithSize(12.0+fontScale);
        closebtn.backgroundColor = [UIColor clearColor];
        closebtn.tag = 10+i;
        [closebtn addTarget:self action:@selector(itemBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [bottomView addSubview:closebtn];
        [closebtn setButtonContentCenter];
        if (i != 0)
        {
            UIView *lineBview = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-180*displaywidth+60*displaywidth*i, 12.5*displaywidth, 1, 25*displaywidth)];
            lineBview.backgroundColor = RGB(204, 204, 204);
            [bottomView addSubview:lineBview];
        }
        if (i == 2)
        {
            focusonBtn = closebtn;
        }
        
        
    }
}

- (void)itemBtnAction:(UIButton *)btn
{
    if (btn.tag == 10)
    {
        //分享
        if (![LTools storageForKey:SERVER_IsLogin])
        {
            [LTools showMBProgressWithText:@"请先登录" addToView:self.view];
            return;
        }
        UserAccountModel *model = [UserAccountModel shareMange];
        ShareManager *manager = [ShareManager shareToManager];
        manager.title = @"专线网";
        manager.descriptionStr = [NSString stringWithFormat:@"%@司机的货车详情信息，有货就联系他吧...",_carModel.linkman];
        manager.imgUrl = @"logo3x60";
        manager.logoimgUrl = nil;
        if (logoimage)
        {
            manager.logoimgUrl = logoimage;
        }
        manager.webUrl = [NSString stringWithFormat:@"https://new.wuliu.xin/truckDetail?id=%@&inviteUserId=%ld",_carID,model.ID];
        
    }
    else if (btn.tag == 11)
    {
        //投诉
        ComplaintsViewController *vc = [[ComplaintsViewController alloc] init];
        vc.titStr = @"投诉";
        vc.joinStr = _carID;
        vc.typeStr = @"1";
        [self.navigationController pushViewController:vc animated:YES];
        
        
    }
    else if (btn.tag == 12)
    {
        //关注
        WEAKSELF;
        NSDictionary *dic = @{@"type":@"2",
                              @"joinId":_carID};
        [HYBaseHandler requestWithTheFormUrl:SERVER_phoneBook Parmers:dic Success:^(id obj) {
            if ([obj server_Getcodecheck])
            {
                NSString *msg = s_str(obj[@"msg"]);
                if (![msg containsString:@"取消"])
                {
                    [LTools showMBProgressWithText:@"关注成功" addToView:weakSelf.view];
                    [focusonBtn setTitle:@"已关注" forState:UIControlStateNormal];
                }
                else
                {
                    [LTools showMBProgressWithText:@"取消关注成功" addToView:weakSelf.view];
                    [focusonBtn setTitle:@"关注" forState:UIControlStateNormal];
                }
                [focusonBtn setImage:IMAGE(@"db_nav3") forState:UIControlStateNormal];
                [focusonBtn setButtonContentCenter];
            }
            else
            {
                [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
            }
        } failed:^(NSError *error) {
            
        }];
    }
    else
    {
        //电话
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_carModel.phone]]];

    }
}


//我要评论
- (void)commentAction
{
    UserAccountModel *userModel = [UserAccountModel shareMange];
    if (![LTools storageForKey:SERVER_IsLogin])
    {
        [LTools showMBProgressWithText:@"请先登录" addToView:self.view];
        return;
    }
    if (userModel.isIdentify != 1)
    {
        [LTools showMBProgressWithText:@"请先实名认证" addToView:self.view];
        return;
    }
    VanCommentViewController *vc = [[VanCommentViewController alloc] init];
    vc.carID = _carID;
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 4)
    {
        return _commentAry.count;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor whiteColor];
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10*displaywidth)];
    lineView.backgroundColor = BacksColor;
    [cell.contentView addSubview:lineView];
    if (indexPath.section == 0)
    {
        lineView.backgroundColor = [UIColor whiteColor];
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 15*displaywidth, 50*displaywidth, 50*displaywidth) ImageName:@"morenFace"];
        if (_carModel.headImg > 0)
        {
            [imgView sd_setImageWithURL:[NSURL URLWithString:_carModel.headImg] placeholderImage:[UIImage imageNamed:@"morenFace"]];
        }
        imgView.contentMode = UIViewContentModeScaleAspectFill;
        imgView.layer.cornerRadius = 25*displaywidth;
        imgView.layer.masksToBounds = YES;
        [cell.contentView addSubview:imgView];
        NSString *busy = @"有空";
        UIColor *backCols = RGB(230, 67, 64);
        if ([_carModel.busy integerValue] == 1)
        {
            busy = @"没空";
            backCols = BacksColor;
        }
        UILabel *typeLabel = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH- 50*displaywidth, 20*displaywidth, 35*displaywidth, 15*displaywidth) Font:11.0 Text:busy Color:[UIColor whiteColor]];
        typeLabel.textAlignment = NSTextAlignmentCenter;
        typeLabel.backgroundColor = backCols;
        typeLabel.layer.cornerRadius = 2*displaywidth;
        typeLabel.layer.masksToBounds = YES;
        [cell.contentView addSubview:typeLabel];
        
        UILabel *comNameLab = [ZCControl createLabelWithFrame:CGRectMake(75*displaywidth, 15*displaywidth, SCREEN_WIDTH-130*displaywidth, 25*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"%@-%@",_carModel.linkman,_carModel.carNumber] Color:BlaTitColor];
        comNameLab.textAlignment = NSTextAlignmentLeft;
        NSMutableAttributedString *title11 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@-%@",_carModel.linkman,_carModel.carNumber]];
        NSRange titleRange01 = [[title11 string]rangeOfString:[NSString stringWithFormat:@"-%@",_carModel.carNumber]];
        [title11 addAttribute:NSForegroundColorAttributeName value:YellowColor range:titleRange01];
        comNameLab.attributedText = title11;
        [cell.contentView addSubview:comNameLab];
       
        UILabel *addressLab = [ZCControl createLabelWithFrame:CGRectMake(75*displaywidth, 45*displaywidth, SCREEN_WIDTH-150*displaywidth, 20*displaywidth) Font:10.0 Text:string(@"停车地：", _carModel.parkStation) Color:RGB(154, 154, 154)];
        addressLab.textAlignment = NSTextAlignmentLeft;
        [cell.contentView addSubview:addressLab];
        CGFloat distance = [_carModel.distance floatValue]/1000.0;
        NSString *string = [NSString stringWithFormat:@"%.1lfkm",distance];
        if (distance == 0)
        {
            string = @"0km";
        }
        UILabel *distanceLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-70*displaywidth, 45*displaywidth, 70*displaywidth, 20*displaywidth) Font:10.0 Text:string Color:RGB(154, 154, 154)];
        distanceLab.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:distanceLab];
        
    }
    else if (indexPath.section == 1)
    {
        CGFloat H = 25*displaywidth;
        if (_carModel.imgs.length > 0)
        {
            H = 140*displaywidth;
            NSArray *imgAry = [_carModel.imgs componentsSeparatedByString:@","];
            NSInteger num = imgAry.count;
            if (imgAry.count > 3)
            {
                num = 3;
            }
            CGFloat Width = (SCREEN_WIDTH-70*displaywidth)/3;
            for (int i = 0; i < num; i++)
            {
                UIImageView *imageView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth+(Width+20*displaywidth)*i, 25*displaywidth, Width, 100*displaywidth) ImageName:@"newsImage"];
                if (imgAry[i] > 0)
                {
                    [imageView sd_setImageWithURL:[NSURL URLWithString:imgAry[i]] placeholderImage:[UIImage imageNamed:@"newsImage"]];
                }
                imageView.contentMode = UIViewContentModeScaleAspectFill;
                imageView.layer.masksToBounds = YES;
                [cell.contentView addSubview:imageView];
                
            }
        }
        NSString *wb = @"无";
        if ([_carModel.baffle integerValue] == 1)
        {
            wb = @"有";
        }
        NSArray *typeAry = @[@"车型",@"宽高",@"载重",@"尾板"];
        NSArray *nameAry = @[[NSString stringWithFormat:@"%@米%@",_carModel.length,_carModel.truckType],[NSString stringWithFormat:@"宽%@米 高%@米",_carModel.width,_carModel.high],[NSString stringWithFormat:@"%@吨",_carModel.bearLimit],wb];
        for (int i = 0; i < typeAry.count; i++)
        {
            UILabel *typeLabel = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth+(SCREEN_WIDTH/2)*(i%2), H+35*displaywidth*(i/2), 35*displaywidth, 20*displaywidth) Font:12.0 Text:typeAry[i] Color:RGB(36, 201, 181)];
            typeLabel.textAlignment = NSTextAlignmentCenter;
            typeLabel.backgroundColor = RGB(236, 254, 255);
            typeLabel.layer.cornerRadius = 2;
            typeLabel.layer.masksToBounds = YES;
            [cell.contentView addSubview:typeLabel];
            
            UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(55*displaywidth+(SCREEN_WIDTH/2)*(i%2), H+35*displaywidth*(i/2),SCREEN_WIDTH/2-60*displaywidth, 20*displaywidth) Font:12.0 Text:nameAry[i] Color:BlaTitColor];
            nameLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0];
             [cell.contentView addSubview:nameLab];
        }
        
    }
    else if (indexPath.section == 2)
    {
        NSString *timeString = [self timeIntervalFromLastTime:_carModel.truckLine.returnDtm lastTimeFormat:@"yyyy-MM-dd HH:mm:ss"];
        if (![timeString isEqualToString:@"已过期"])
        {
            UIView *lineCview = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, 22.5*displaywidth, 2*displaywidth, 15*displaywidth)];
            lineCview.backgroundColor = ThemeColor;
            [cell.contentView addSubview:lineCview];
            UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(25*displaywidth, 15*displaywidth, 120*displaywidth, 30*displaywidth) Font:15.0 Text:@"回程信息" Color:ThemeColor];
            [cell.contentView addSubview:titLab];
            UILabel *timeLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-180*displaywidth, 15*displaywidth, 165*displaywidth, 25*displaywidth) Font:10.0 Text:timeString Color:RGB(187, 187, 187)];
            NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:timeString];
            NSRange startRange1 = [timeString rangeOfString:@"："];
            NSRange endRange1 = [timeString rangeOfString:@"天"];
            NSRange range1 = NSMakeRange(startRange1.location + startRange1.length, endRange1.location - startRange1.location - startRange1.length);
            NSString *str = [timeString stringByReplacingOccurrencesOfString:@"倒计时：" withString:@""];
            NSRange endRange2 = [str rangeOfString:@"时"];
            NSRange range2 = NSMakeRange(endRange1.location + endRange1.length, endRange2.location+4 - endRange1.location - endRange1.length);
            NSRange endRange3 = [timeString rangeOfString:@"分"];
            NSRange range3 = NSMakeRange(endRange2.location+4 + endRange2.length, endRange3.location - endRange2.location-4 - endRange2.length);
            [title addAttribute:NSForegroundColorAttributeName value:YellowColor range:range1];
            [title addAttribute:NSForegroundColorAttributeName value:YellowColor range:range2];
            [title addAttribute:NSForegroundColorAttributeName value:YellowColor range:range3];
            [title addAttribute:NSFontAttributeName value:NormalFontWithSize(12.0+fontScale) range:range1];
            [title addAttribute:NSFontAttributeName value:NormalFontWithSize(12.0+fontScale) range:range2];
            [title addAttribute:NSFontAttributeName value:NormalFontWithSize(12.0+fontScale) range:range3];
            timeLab.textAlignment = NSTextAlignmentRight;
            timeLab.attributedText = title;
            [cell.contentView addSubview:timeLab];
            UIView *lineDView = [[UIView alloc] initWithFrame:CGRectMake(0, 50*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
            lineDView.backgroundColor = BacksColor;
            [cell.contentView addSubview:lineDView];
            UIImageView *startImgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 62.5*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:@"congicon"];
            startImgView.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:startImgView];
            UILabel *startALab = [ZCControl createLabelWithFrame:CGRectMake(35*displaywidth, 55*displaywidth, SCREEN_WIDTH-50*displaywidth, 30*displaywidth) Font:13.0 Text:_carModel.truckLine.shipmentText Color:BlaTitColor];
            [cell.contentView addSubview:startALab];
            UIView *lineEView = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, 90*displaywidth, SCREEN_WIDTH-30*displaywidth, 1*displaywidth)];
            lineEView.backgroundColor = BacksColor;
            [cell.contentView addSubview:lineEView];
            UIImageView *stopImgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 102.5*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:@"daoicon"];
            stopImgView.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:stopImgView];
            UILabel *stopALab = [ZCControl createLabelWithFrame:CGRectMake(35*displaywidth, 95*displaywidth, SCREEN_WIDTH-50*displaywidth, 30*displaywidth) Font:13.0 Text:_carModel.truckLine.destinationText Color:BlaTitColor];
            [cell.contentView addSubview:stopALab];
        }
    }
    else if (indexPath.section == 3)
    {
        CDZStarsControl *starsControl = [[CDZStarsControl alloc] initWithFrame:CGRectMake(130*displaywidth, 30*displaywidth,200*displaywidth, 40*displaywidth) stars:5 starSize:CGSizeMake(35*displaywidth, 35*displaywidth) noramlStarImage:[UIImage imageNamed:@"star_normal"] highlightedStarImage:[UIImage imageNamed:@"star01"]];
        starsControl.delegate = self;
        starsControl.allowFraction = YES;
        starsControl.score = [_carModel.avgRate floatValue];
        starsControl.isEntlab = NO;
        [cell.contentView addSubview:starsControl];
        UILabel *numLab = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 10*displaywidth, 90*displaywidth, 80*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"%@\n综合信誉",_carModel.avgRate] Color:RGB(153, 153, 153)];
        numLab.textAlignment = NSTextAlignmentCenter;
        NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n综合信誉",_carModel.avgRate]];
        NSRange titleRange = [[title string]rangeOfString:[NSString stringWithFormat:@"%@",_carModel.avgRate]];
        [title addAttribute:NSForegroundColorAttributeName value:RGB(255, 51, 51) range:titleRange];
        [title addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:32] range:titleRange];
        numLab.attributedText = title;
        [cell.contentView addSubview:numLab];
        UIView *lineDview = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, 90*displaywidth, SCREEN_WIDTH-30*displaywidth, 1*displaywidth)];
        lineDview.backgroundColor = BacksColor;
        [cell.contentView addSubview:lineDview];
        NSArray *labAry = _carModel.labels;
        if (labAry.count > 0)
        {
            CGFloat h2 = 105*displaywidth;
            CGFloat w2 = 0;
            CGFloat width = SCREEN_WIDTH;
            for (int i = 0; i < labAry.count; i++)
            {
                GoodsAddressModel *sizeModel = labAry[i];
                NSString *typename = [NSString stringWithFormat:@"%@(%@)",sizeModel.name,sizeModel.count];
                UIButton *tasteBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth+i*75*displaywidth, h2, 60*displaywidth, 25*displaywidth) ImageName:nil Target:nil Action:nil Title:typename Font:12.0];
                tasteBtn.tag = 500+i;
                NSDictionary *attributes = @{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)};
                CGFloat length = [typename boundingRectWithSize:CGSizeMake(2000, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
                if (length > width-45*displaywidth)
                {
                    length = width-45*displaywidth;
                }
                tasteBtn.frame = CGRectMake(15*displaywidth + w2, h2, length + 15*displaywidth , 25*displaywidth);
                if(15*displaywidth + w2 + length + 15*displaywidth > width){
                    w2 = 0; //换行时将w置为0
                    h2 = h2 + tasteBtn.frame.size.height + 20*displaywidth;//距离父视图也变化
                    tasteBtn.frame = CGRectMake(15*displaywidth + w2, h2, length + 15*displaywidth, 25*displaywidth);//重设button的frame
                }
                w2 = tasteBtn.frame.size.width + tasteBtn.frame.origin.x+10*displaywidth;
                
                UIColor *bordercolor2 = BacksColor;
                UIColor *titcolor2 = BlaTitColor;
                [tasteBtn setTitleColor:titcolor2 forState:UIControlStateNormal];
                tasteBtn.layer.cornerRadius = 12.5*displaywidth;
                tasteBtn.layer.masksToBounds = YES;
                tasteBtn.backgroundColor = bordercolor2;
                [cell.contentView addSubview:tasteBtn];
                
            }
            
        }
    }
    else
    {
        if (_commentAry.count > 0)
        {
            CommentModel *model = _commentAry[indexPath.row];
            UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 25*displaywidth, 50*displaywidth, 50*displaywidth) ImageName:@"morenFace"];
            imgView.layer.cornerRadius = 25*displaywidth;
            imgView.layer.masksToBounds = YES;
            if (model.headImg.length > 0)
            {
                [imgView sd_setImageWithURL:[NSURL URLWithString:model.headImg] placeholderImage:[UIImage imageNamed:@"morenFace"]];
            }
            [cell.contentView addSubview:imgView];
            NSString *name = model.username;
            if ([model.isAnonymous integerValue] == 1)
            {
                name = @"匿名用户";
            }
            UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(75*displaywidth, 25*displaywidth, SCREEN_WIDTH-170*displaywidth, 20*displaywidth) Font:15.0 Text:name Color:RGB(32, 69, 139)];
            [cell.contentView addSubview:nameLab];
            UILabel *timeLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-140*displaywidth, 25*displaywidth, 125*displaywidth, 20*displaywidth) Font:10.0 Text:model.createDtm Color:RGB(185, 185, 185)];
            timeLab.numberOfLines = 0;
            timeLab.textAlignment = NSTextAlignmentRight;
            [cell.contentView addSubview:timeLab];
            UILabel *contenLab = [ZCControl createLabelWithFrame:CGRectMake(75*displaywidth, 45*displaywidth, SCREEN_WIDTH-120*displaywidth, 45*displaywidth) Font:12.0 Text:model.content Color:BlaTitColor];
            [cell.contentView addSubview:contenLab];
        }
        
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 80*displaywidth;
    }
    else if (indexPath.section == 1)
    {
        return 210*displaywidth;
    }
    else if (indexPath.section == 2)
    {
        NSString *timeString = [self timeIntervalFromLastTime:_carModel.truckLine.returnDtm lastTimeFormat:@"yyyy-MM-dd HH:mm:ss"];
        if (![timeString isEqualToString:@"已过期"])
        {
            return 130*displaywidth;
        }
        return 0;
    }
    else if (indexPath.section == 3)
    {
        CGFloat h2 = 90*displaywidth;
        CGFloat w2 = 0;
        CGFloat width = SCREEN_WIDTH;
        NSArray *labAry = _carModel.labels;
        if (labAry.count > 0)
        {
            h2 = 105*displaywidth;
            for (int i = 0; i < labAry.count; i++)
            {
                GoodsAddressModel *sizeModel = labAry[i];
                NSString *typename = [NSString stringWithFormat:@"%@(%@)",sizeModel.name,sizeModel.count];
                NSDictionary *attributes = @{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)};
                CGFloat length = [typename boundingRectWithSize:CGSizeMake(2000, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
                if (length > width-45*displaywidth)
                {
                    length = width-45*displaywidth;
                }
                if(15*displaywidth + w2 + length + 15*displaywidth > width){
                    w2 = 0; //换行时将w置为0
                    h2 = h2 + 25 + 20*displaywidth;//距离父视图也变化
                }
                w2 = length + 15*displaywidth + 15*displaywidth + w2;
            }
            h2+=40*displaywidth;
        }
        
        return h2;
    }
    return 95*displaywidth;
}

- (void)requestTtuckSelect
{
    WEAKSELF;
    NSDictionary *dic = @{@"id":_carID};
    [HYBaseHandler requestWithTheFormUrl:SERVER_CarSelect Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            _carModel = [CarDetailModel mj_objectWithKeyValues:obj[@"data"]];
            _carModel.distance = _distance;
            if (_carModel.user.headImg.length > 0)
            {
                logoimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_carModel.user.headImg]]];
                [logoimage jkr_compressToDataLength:3200 withBlock:^(NSData *data) {
                    UIImage *imageOne = [UIImage imageWithData:data];
                    logoimage = imageOne;
                }];
               
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                if ([_carModel.isCollect integerValue] == 1)
                {
                    [focusonBtn setTitle:@"已关注" forState:UIControlStateNormal];
                    [focusonBtn setImage:IMAGE(@"db_nav3") forState:UIControlStateNormal];
                    [focusonBtn setButtonContentCenter];
                }
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
    }];
}

- (void)requestCommentList
{
    WEAKSELF;
    NSDictionary *dic = @{@"joinId":_carID,
                          @"type":@"3",
                          @"size":@"9999"
                          };
    [HYBaseHandler requestWithTheFormUrl:SERVER_commentList Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            weakSelf.commentAry = [CommentModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (NSString *)timeIntervalFromLastTime:(NSString *)lastTime lastTimeFormat:(NSString *)format1
{
    //上次时间
    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc]init];
    dateFormatter1.dateFormat = format1;
    NSDate *lastDate = [dateFormatter1 dateFromString:lastTime];
    //当前时间
    //    NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc]init];
    //    dateFormatter2.dateFormat = @"yyyy/MM/dd HH:mm:ss";
    //    NSDate *currentDate = [dateFormatter2 dateFromString:currentTime];
    return [self timeIntervalFromLastTime:lastDate ToCurrentTime:[NSDate date]];
    
}
- (NSString *)timeIntervalFromLastTime:(NSDate *)lastTime ToCurrentTime:(NSDate *)currentTime
{
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    //上次时间
    NSDate *lastDate = [lastTime dateByAddingTimeInterval:[timeZone secondsFromGMTForDate:lastTime]];
    //当前时间
    NSDate *currentDate = [currentTime dateByAddingTimeInterval:[timeZone secondsFromGMTForDate:currentTime]];
    //时间间隔
    NSInteger intevalTime = [lastDate timeIntervalSinceReferenceDate] - [currentDate timeIntervalSinceReferenceDate];
    
    //秒、分、小时、天、月、年
    NSInteger minutes = intevalTime / 60;
    NSInteger hours = intevalTime / 60 / 60;
    NSInteger day = intevalTime / 60 / 60 / 24;
    NSInteger month = intevalTime / 60 / 60 / 24 / 30;
    NSInteger yers = intevalTime / 60 / 60 / 24 / 365;
    if (minutes <= 0)
    {
        return @"已过期";
    }
    if (minutes < 60)
    {
        return  [NSString stringWithFormat:@"倒计时：0天0时%ld分",minutes];
    }
    else if (hours < 24)
    {
        minutes = minutes%60;
        return  [NSString stringWithFormat:@"倒计时：0天%ld时%ld分",hours,minutes];
    }else if (day >= 1)
    {
        hours = hours%24;
        minutes = minutes%60;
        return  [NSString stringWithFormat:@"倒计时：%ld天%ld时%ld分",day,hours,minutes];
    }
    return @"";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
